<?php
class Index extends CI_Controller {
	public function __construct() {
		parent::__construct ();
		// 登录校验
		$this->common->check_login_admin ();
		$this->load->helper ( array (
				'form',
				'url' 
		) );
	}
	
	// 首页
	public function index() {
		$this->load->model ( 'Web_message_model' );
		$data ['web_message'] = $this->Web_message_model->web_message ();
		
		$sql = "SELECT * FROM pc_ddth_aixinchi WHERE id = '1'";
		$query = $this->db->query ( $sql );
		$query = $query->row_array ();
		$data ['aixinchi'] = $query ['aixinchi'];
		$data['pipei_num'] = $query['pipei_num'];
		$data['start_time'] = $query['start_time'];
		$data['end_time'] = $query['end_time'];
		$data ['left'] = $this->load->view ( 'admin/left', '', TRUE );
		$data ['menu'] = $this->load->view ( 'admin/menu', '', TRUE );
		
		$this->load->view ( 'admin/index', $data );
	}
	
	/**
	 * 修改信息
	 */
	public function update_web_message() {
		$data = array (
				'pipei_num' => $_POST ['pipei_num'],
				'start_time' => $_POST ['start_time'],
				'end_time' => $_POST ['end_time'],
				'aixinchi' => $_POST ['aixinchi'],
		);
		
		$result = $this->db->update ( 'pc_ddth_aixinchi', $data, array (
				'id' => '1' 
		) );
		
		// $path = $this->do_upload ( "logo" );
		
		// $this->load->model ( 'Web_message_model' );
		// $result = $this->Web_message_model->update_web_message ( $_POST ['id'],$path ['file_name'] );
		
		if ($result) {
			exit ( $this->common->alert_msg_url ( '修改成功', site_url ( 'admin/index' ) ) );
		} else {
			exit ( $this->common->alert_msg_goback ( '修改失败' ) );
		}
	}
	
	/* 保存图片 */
	public function do_upload($name) {
		$config ['upload_path'] = './public/img/';
		$config ['allowed_types'] = 'gif|jpg|png|bmp';
		$config ['max_size'] = 10000;
		$config ['max_width'] = 102400;
		$config ['max_height'] = 76800;
		
		$this->load->library ( 'upload', $config );
		
		if (! $this->upload->do_upload ( $name )) {
			$path = $this->upload->display_errors ();
		} else {
			$path = $this->upload->data ();
		}
		
		return $path;
	}
}